<!doctype html>
<html>
<head>
    <script src="../js/angular.min.js"></script>
</head>
<body>
<div ng-app="myApp">

    <div ng-controller="MyController">
        <input ng-model="expr"
               type="text"
               placeholder="Enter an expression" />
        <h2>{{ parseValue }}</h2>
    </div>

</div>
<script type="text/javascript">

    var app = angular.module("myApp",[]);
    app.controller('MyController',function($scope,$parse){

        $scope.$watch('expr',function(newVal,oldVal,scope){
            if(newVal != oldVal){
                console.log("in")
                // 用该表达式设置parseFun
                var parseFun = $parse(newVal);
                // 获取经过解析后表达式的值
                $scope.parsedValue = parseFun(scope);
            }
        });
    });

</script>
</body>
</html>